<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="content-type" content="text/html;charset=utf-8">
  <title><%= title %></title>
  <link rel="stylesheet" href="stylesheets/bootstrap.min.css" media="screen">
  <style type="text/css">
    .m15{ margin: 15px;}
    .tc{ text-align: center;font-size: 18px;font-weight: 600;}
  </style>
</head>
<body screen_capture_injected="true">
<div class="container">
  <form class="col-sm-offset-4 col-sm-4 form-horizontal" role="form" method="post" onsubmit="return false">
    <fieldset>
      <legend></legend>
      <div class="panel panel-default">
        <div class="panel-heading">
          <p class="tc">请先登录</p>
        </div>
        <div class="panel-body m15">
          <div class="form-group">
            <div class="input-group">
                        <span class="input-group-addon">
                        <span class="glyphicon glyphicon-user"></span>
                        </span>
              <input type="text" class="form-control" id="username" name="username" placeholder="请输入用户名" required>
            </div>
          </div>
          <div class="form-group">
            <div class="input-group">
                        <span class="input-group-addon">
                        <span class="glyphicon glyphicon-lock"></span>
                        </span>
              <input type="text" class="form-control" id="password" name="password" placeholder="请输入密码" required>
            </div>
          </div>
          <div class="form-group">
            <button type="button" class="btn btn-primary btn-block" id="login0">登录</button>
          </div>
          <div class="form-group">
            <button type="button" style="width: 150px;float: left;margin:15px 5px 0px 8px" class="btn btn-primary btn-block" id="chat">进入聊天室</button>
            <button type="button" style="width: 150px;float: left;margin-top: 15px;" class="btn btn-danger btn-block" id="register0">注册</button>
            <button type="button" style="width: 150px;float: left;margin-top: 15px;" class="btn btn-danger btn-block" id="upload">上传</button>
          </div>
        </div>
      </div>
    </fieldset>
  </form>
</div>

<script type="text/javascript" src="javascripts/bootstrap.min.js"></script>
<script type="text/javascript" src="javascripts/jquery.js"></script>
<script type="text/javascript" src="javascripts/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="javascripts/socket.io.js"></script>
<script type="text/javascript" src="javascripts/layer/layer.js"></script>
<script type="text/javascript">
//  var socket=io.connect("http://192.168.1.105:8888");
  var socket=io.connect("http://localhost:8888");
      socket.on("server",function(evt){
        var obj = eval(evt.data);
        var code=obj[0]["code"];
        if(code!=1){
          alert("链接服务器失败，请重新登录!")
          location.href="index/index";
        }
  })
  $(function(){
    $("#register0").click(function(){
      location.href = 'index/reg';
      });
    $("#upload").click(function(){
      location.href = 'index/upload';
    })
    $("#login0").click(function(){
      var username = $("#username").val();
      var password = $("#password").val();
      if(username==''||username==undefined||username==null){
        alert("请输入账号");
        return;
      }
      if(password==null||password==undefined||password==''){
        alert("请输入密码");
        return;
      }
      var data = {"uname":username,"upwd":password};
      $.ajax({
        url:'index/login',
        type:'post',
        data: data,
        success: function(data){
           var d=eval(data);
          if(d.code==10){
            location.href = 'index/page';
          }
          if(d.code==11){
            alert(d.msg);
          }
        },
        error: function(data){
            location.href = 'index/login';
        }
      });
    });
    $("#chat").click(function(){

      location.href="/chat";
//
    });
  });
</script>
</body>
</html>